package gbench.appdemo.myworld.data;

import static gbench.common.tree.LittleTree.MFT;

import java.util.List;
import gbench.common.tree.LittleTree.IRecord;
import gbench.commonApp.data.DataApp;

/**
 * 
 * @author gbench
 *
 */
public class MyDataApp extends DataApp {
    
    /**
     * 获取MyDataApp
     * @param name 数据库名称
     */
    public MyDataApp(final String name){
        this.dbname = name;
        this.reload(this.configureDbName(name));
    }
    
    /**
     * 数据查询
     * @param sql sql 语句
     * @return IRecord 集合
     */
    public List<IRecord> sqlquery(final String sql,String dbname) {
        reload(this.configureDbName(dbname));
        return this.jdbc.sql2records(sql);
    }
    
    /**
     * 数据查询
     * @param sql sql 语句
     * @return IRecord 集合
     */
    public List<IRecord> sqlquery(final String sql) {
        return this.sqlquery(sql,dbname);
    }
    
    public String getDbname() {
        return dbname;
    }

    public void setDbname(String dbname) {
        this.dbname = dbname;
    }

    /**
     * 配置数据库
     * @param dbname
     * @return 设定数据库
     */
    public IRecord configureDbName(final String dbname) {
        return cfg.derive("url", MFT("jdbc:mysql://localhost:3306/{0}?serverTimezone=GMT%2B8", dbname));
    }
    
    private String dbname;  //加入 默认数据库

}
